package com.friend.controller;

import com.friend.model.DemoBean;
import com.friend.model.Plc;
import com.friend.service.PlcService;
import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xingshuang
 */
@RestController
@RequestMapping("/serializer")
public class S7SerializerComController {

    @Autowired
    private S7Serializer s7Serializer;
    @Autowired
    private PlcService plcService;

    @GetMapping("/bean")
    public ResponseEntity<DemoBean> demoBean() {
        DemoBean bean = this.s7Serializer.read(DemoBean.class);
        return ResponseEntity.ok(bean);
    }


    @GetMapping("/test")
    public String test() {
        Plc p=new Plc();
       // p.setId(1L);
        p.setData("1");
        plcService.save(p);
        return "ok";
    }
}
